package com.leoman.dao;

import com.leoman.entity.UserLetterMind;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * UserLetterMindDao
 * Created by 涂奕恒 on 2016/11/23 0023 下午 3:46.
 */
public interface UserLetterMindDao extends JpaRepository<UserLetterMind, Integer>, JpaSpecificationExecutor<UserLetterMind> {

    @Query("select a from UserLetterMind a where a.user.id = ?1 and a.sourceId = ?2 and a.sourceType = ?3")
    UserLetterMind findOneByParams(Integer userId, Integer sourceId, Integer type);

    @Query("select a from UserLetterMind a where a.user.id = ?1 and a.sourceType = 2 and 0 = (select b.isDraft from Mind b where b.id = a.sourceId)")
    Page<UserLetterMind> iPageByParamsPlus(Integer userId, Pageable pageable);
}